﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using QuanLyVanBanBUS;

public partial class Home : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack == false)
        {
            layDanhSachVanBanDaDuyetCapChiNhanh();

            layDanhSachVanBanDaDuyetCapPhongTo();

            layDanhSachNguoiDungNhanVanBanTrongNgay();
        }
    }

    protected void layDanhSachNguoiDungNhanVanBanTrongNgay()
    {
        NoiNhanBUS nnBUS = new NoiNhanBUS();
        dlstDanhSachNguoiDungNhanVanBanTrongNgay.DataSource = nnBUS.layDanhSachNguoiDungNhanVanBanTrongNgay();
        dlstDanhSachNguoiDungNhanVanBanTrongNgay.DataBind();
    }
    protected void layDanhSachVanBanDaDuyetCapChiNhanh()
    {
        VanBanBUS vbBUS = new VanBanBUS();

        gvVanBanChiNhanh.DataSource = vbBUS.layDanhSachVanBanDaDuyetCapChiNhanh();

        gvVanBanChiNhanh.DataBind();
    }
    protected void layDanhSachVanBanDaDuyetCapPhongTo()
    {
        VanBanBUS vbBUS = new VanBanBUS();

        gvVanBanPhongTo.DataSource = vbBUS.layDanhSachVanBanDaDuyetCapPhongTo();

        gvVanBanPhongTo.DataBind();
    }
    protected void gvVanBanChiNhanh_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvVanBanChiNhanh.PageIndex = e.NewPageIndex;

        layDanhSachVanBanDaDuyetCapChiNhanh();
    }
    protected void gvVanBanPhongTo_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvVanBanPhongTo.PageIndex = e.NewPageIndex;

        layDanhSachVanBanDaDuyetCapPhongTo();
    }
    protected void dlstDanhSachNguoiDungNhanVanBanTrongNgay_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemIndex >= 0)
        {
            Label lblMaNguoiNhan = (Label)e.Item.FindControl("lblMaNguoiNhan");
            Label lblNgayNhanGanNhat = (Label)e.Item.FindControl("lblNgayNhanGanNhat");

            NoiNhanBUS nnBUS = new NoiNhanBUS();
            NoiNhan nnDTO = new NoiNhan();
            nnDTO.MaNguoiNhan = dlstDanhSachNguoiDungNhanVanBanTrongNgay.DataKeys[e.Item.ItemIndex].ToString();
            lblNgayNhanGanNhat.Text = nnBUS.layNgayNhanGanNhatTheoMaNguoiDung(nnDTO);
            if (lblNgayNhanGanNhat.Text.Length > 8)
            {
                lblNgayNhanGanNhat.Text = lblNgayNhanGanNhat.Text.Substring(0, 8);
            }

            //Hien thi Tooltips nhung van ban nhan duoc
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                VanBanBUS vbBUS = new VanBanBUS();
                List<string> lst = new List<string>();
                IList<VanBan> lstVanBan = vbBUS.layDanhSachVanBanDaNhanTrongNgayTheoMaNguoiNhan(nnDTO);
                foreach (VanBan vb in lstVanBan)
                {
                    lblMaNguoiNhan.ToolTip += vb.SoVanBan.ToString() + ";" + " " + "\n";
                    lblNgayNhanGanNhat.ToolTip += vb.SoVanBan.ToString() + ";" + " " + "\n";
                }
            }
        }
    }
    protected void tmrDanhSachNguoiDungNhanVanBanTrongNgay_Tick(object sender, EventArgs e)
    {
        layDanhSachNguoiDungNhanVanBanTrongNgay();
    }
}